package javango.forms;

import java.util.List;
import java.util.Map;

import javango.forms.fields.BoundField;
import javango.forms.fields.Field;

public interface Form extends Iterable<BoundField> {

	/**
	 * Returns true if this is a bound form,  bound forms have been associated with input from a user.
	 * @return
	 */
	public boolean isBound();
	
	/**
	 * Bind the form to the input values from the user.
	 * @param m
	 */
	public Form bind(Map<String, String[]> m);
	
	/**
	 * Return true if this form is valid.
	 * @return
	 */
	public boolean isValid();
	
	/**
	 * Returns a Map of field errors
	 * TODO If we go with Hibernate validator, should this return a Map/List of hibernate validators
	 * @return
	 */
	public Map<String, String> getErrors();
	
	/**
	 * Cleans the data in this form into a new bean of the specified class.
	 * @param objectClass
	 * @return
	 */
	public Object clean(Class objectClass);
	
	/**
	 * Cleans the data in this form into the provided bean.
	 * @param bean
	 * @return
	 */
	public Object clean(Object bean);

	public String asTable();
	
	public Map<String, Object> getCleanedData();
	
	public Map<String, String[]> getData();
	
	public Map<String, Field> getFields();
	
	public Map<String, Object> getInitial();
	
	public Form setPrefix(String prefix);
	public String getPrefix();
	
	/**
	 * Takes either a format string (id_%s) or null to disable ids.
	 * 
	 * @param id
	 * @return
	 */
	public Form setId(String id);
	public String getId();
	
	/**
	 * Returns a bound field for the requested field.
	 * @param field
	 * @return
	 */

	public BoundField get(String field);
	
	public List<String> getNonFieldErrors();
	
	
}
